{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-01-22T12:50:49.872257Z",
     "start_time": "2025-01-22T12:48:59.007485Z"
    }
   },
   "source": [
    "#导入cv模块\n",
    "import cv2 as cv\n",
    "\n",
    "#读取图片\n",
    "img = cv.imread('zidane.jpg')\n",
    "\n",
    "#灰度转换\n",
    "gray_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY)#后面是灰度图\n",
    "#显示灰度图\n",
    "cv.imshow('gray',gray_img)\n",
    "#保存灰度图片\n",
    "cv.imwrite('gray_zidane.jpg',gray_img)\n",
    "\n",
    "#显示图片\n",
    "cv.imshow('read_img', img)\n",
    "\n",
    "#等待 0是无限等待下去，waitkey（）参数是等待的时间\n",
    "cv.waitKey(0)\n",
    "\n",
    "#释放内存\n",
    "cv.destroyAllWindows()"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "613628af3578f4a1"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
